package com.mis.pos.service.impl;

import com.mis.pos.entity.UserEntity;
import com.mis.pos.repository.UserRepository;
import com.mis.pos.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;

/**
 * @description:
 * @author: yuxiang
 * @create: 2019-12-12 16:04
 **/
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserRepository userRepository;

    @Transactional
    @Override
    public UserEntity findByUsername(String username) {
        return userRepository.findUserEntityByUsername(username);
    }

    @Override
    public UserEntity updateUser(UserEntity userEntity) {
        //todo 更新用户邮箱 密码基本信息
//        return userRepository.updateUser(userEntity.ge);
        return null;
    }

    @Override
    public UserEntity addUser(UserEntity userEntity) {
        return userRepository.save(userEntity);
    }

    @Override
    public int deleteUser(UserEntity userEntity) {
        try {
            userRepository.delete(userEntity);
        }catch (Exception e){
            e.printStackTrace();
            return -1;
        }
        return 0;
    }

    @Override
    public UserEntity findById(Long id) {
        return userRepository.findUserEntityById(id);
    }
}
